/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.momarketing.service;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;
import com.boxin.ims.modules.momarketing.entity.OnlineSignup;
import com.boxin.ims.modules.momarketing.entity.self.OnlineSignupDetail;
import com.boxin.ims.modules.momarketing.dao.OnlineSignupDao;

/**
 * 在线预约Service
 * @author Jakemanse
 * @version 2013-09-10
 */
@Component
@Transactional(readOnly = true)
public class OnlineSignupService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(OnlineSignupService.class);
	
	@Autowired
	private OnlineSignupDao onlineSignupDao;
	
	public OnlineSignup get(Long id) {
		return onlineSignupDao.findOne(id);
	}
	
	public Page<OnlineSignup> find(Page<OnlineSignup> page, OnlineSignup onlineSignup) {
		DetachedCriteria dc = onlineSignupDao.createDetachedCriteria();
		dc.createAlias("onlineSignupConfig", "onlineSignupConfig");
		if (onlineSignup.getUser()!=null && onlineSignup.getUser().getId()>0){
			dc.add(Restrictions.eq("user.id", onlineSignup.getUser().getId()));
		}
		if (onlineSignup.getOnlineSignupConfig()!=null && onlineSignup.getOnlineSignupConfig().getId()>0){
			dc.add(Restrictions.eq("onlineSignupConfig.id", onlineSignup.getOnlineSignupConfig().getId()));
		}
		if (StringUtils.isNotEmpty(onlineSignup.getName())){
			dc.add(Restrictions.like("name", "%"+onlineSignup.getName()+"%"));
		}
		if (StringUtils.isNotEmpty(onlineSignup.getMobile())){
			dc.add(Restrictions.like("mobile", "%"+onlineSignup.getMobile()+"%"));
		}
		if (StringUtils.isNotEmpty(onlineSignup.getQq())){
			dc.add(Restrictions.like("qq", "%"+onlineSignup.getQq()+"%"));
		}
		if (StringUtils.isNotEmpty(onlineSignup.getEmail())){
			dc.add(Restrictions.like("email", "%"+onlineSignup.getEmail()+"%"));
		}
		if (StringUtils.isNotEmpty(onlineSignup.getIdno())){
			dc.add(Restrictions.like("idno", "%"+onlineSignup.getIdno()+"%"));
		}
		if (StringUtils.isNotEmpty(onlineSignup.getRemarks())){
			dc.add(Restrictions.like("remarks", "%"+onlineSignup.getRemarks()+"%"));
		}
		dc.add(Restrictions.eq("delFlag", OnlineSignup.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return onlineSignupDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(OnlineSignup onlineSignup) {
		onlineSignupDao.save(onlineSignup);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		onlineSignupDao.deleteById(id);
	}
	
	

	
}
